package com.zuser.project.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zuser.project.entity.SysUserEntity;
import com.zuser.project.service.SysUserService;
import com.zuser.project.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 用户表
 *
 * @author zuser
 * @email 2076033693@gmail.com
 * @date 2025-04-01 20:53:22
 */
@RestController
@RequestMapping("system/sysuser")
@CrossOrigin
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
//        R page =

        return   sysUserService.queryPage(params);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SysUserEntity sysUser = sysUserService.getById(id);

        return R.ok().put("sysUser", sysUser);
    }

    @PostMapping("/verifyUser")
    public  R verifyUser(@RequestParam("username")String username,@RequestParam("password") String password)
    {
        LambdaQueryWrapper<SysUserEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysUserEntity::getUsername,username);
        wrapper.eq(SysUserEntity::getPassword,password);
        SysUserEntity sysUser = sysUserService.getOne(wrapper);
        if (ObjectUtils.isEmpty(sysUser)) {
                    return  R.error();
        }else {
            return  R.ok().put("token",username+"123333333333"+password);
        }
    }
    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SysUserEntity sysUser){
//        sysUser.setPassword(Math.random()*10+"6e79218965eb72c92a549dd5a33011"+Math.random()*10);
		sysUserService.save(sysUser);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody SysUserEntity sysUser){
		sysUserService.updateById(sysUser);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		sysUserService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
